package com.scsj.supermarket.presenter;

import android.util.Log;

import com.orhanobut.logger.Logger;
import com.scsj.supermarket.base.CollectBase;
import com.scsj.supermarket.bean.BaseBean;
import com.scsj.supermarket.bean.MyCollectGoodsBean;
import com.scsj.supermarket.bean.SelectCollectByUserBean;
import com.scsj.supermarket.model.CollectModel;
import dkmvp.mvp.BasePresenter;
import dkmvp.net.ResponseCallback;
import okhttp3.RequestBody;

/**
 * 商品和店铺收藏查看，收藏和取消收藏presenter
 */

public class CollectPresenter extends BasePresenter implements CollectBase.IPresenter {

    private CollectBase.IModel mModel;
    private CollectBase.IView mView;

    public CollectPresenter(CollectBase.IView view) {
        mView = view;
        mModel = new CollectModel();
    }


    @Override
    public void deliverShopCollectData(RequestBody requestBody) {
        addSubscription(mModel.getShopCollectData(requestBody, new ResponseCallback<SelectCollectByUserBean>() {
            @Override
            public void onSuccess(SelectCollectByUserBean result) {
                if (result.getStatusCode() == 200) {
                    mView.showShopCollectSuccessMsg("获取收藏店铺列表成功", result);
                    Logger.d("获取收藏店铺列表成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("获取收藏店铺列表onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverShopAddAndDelData(RequestBody requestBody) {
        addSubscription(mModel.getShopAddAndDelData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.showShopAddAndDelCollectSuccessMsg("店铺收藏和取消收藏成功");
//                    Logger.d("店铺收藏和取消收藏成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("店铺收藏和取消收藏onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverGoodsCollectData(RequestBody requestBody) {
        addSubscription(mModel.getGoodsCollectData(requestBody, new ResponseCallback<MyCollectGoodsBean>() {
            @Override
            public void onSuccess(MyCollectGoodsBean result) {
                if (result.getStatusCode() == 200) {
                    mView.showGoodsCollectSuccessMsg("查询收藏商品的信息成功", result);
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("查询收藏商品的信息onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverGoodsAddCollectData(RequestBody requestBody) {
        addSubscription(mModel.getGoodsAddCollectData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.showGoodsAddCollectSuccessMsg("用户添加收藏商品成功");
                    Logger.d("用户添加收藏商品成功" + result.toString());
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("用户添加收藏商品onFaild", msg + "");
            }
        }));
    }

    @Override
    public void deliverGoodsDelCollectData(RequestBody requestBody) {
        addSubscription(mModel.getGoodsDelCollectData(requestBody, new ResponseCallback<BaseBean>() {
            @Override
            public void onSuccess(BaseBean result) {
                if (result.getStatusCode() == 200) {
                    mView.showGoodsDelCollectSuccessMsg("用户取消收藏商品成功");
                } else {
                    mView.showErrorMsg(result.getMsg());
                }
            }

            @Override
            public void onFaild(String msg) {
                mView.showErrorMsg(msg);
                Log.e("用户取消收藏商品onFaild", msg + "");
            }
        }));
    }

}
